package com.tm.d10_time;

import java.time.DayOfWeek;
import java.time.LocalDate;

/**
 * 2024/5/24 Cjj LocalDate  15：14
 */
public class Test1_LocalDate {
    public static void main(String[] args) {
        //获取本地日期对象(不可变对象)
        LocalDate ld = LocalDate.now();
        System.out.println(ld);

        //1.获取日期对象中的信息
        int year = ld.getYear();//年
        int month = ld.getMonthValue();//月
        int day = ld.getDayOfMonth();//日
        int dayOfYear = ld.getDayOfYear();//天
        int value = ld.getDayOfWeek().getValue();//星期
        System.out.println(year);
        System.out.println(month);
        System.out.println(day);
        System.out.println(dayOfYear);

        //2.直接修改某个信息:withYear withMonth withDayOfMonth withDayOfYear
        LocalDate ld2 = ld.withYear(2022);
        LocalDate ld3 = ld.withMonth(6);
        System.out.println(ld2);
        System.out.println(ld3);
        System.out.println(ld);

        //3.把某个信息加多少： plusYears  plusMonths plusWeeks plusDays
        LocalDate date = ld.plusYears(2);//2026-05-24
        LocalDate months = ld.plusMonths(2);//2024-07-24
        LocalDate weeks = ld.plusWeeks(2);//2024-06-07
        LocalDate days = ld.plusDays(2);//2024-05-26
        System.out.println(date);
        System.out.println(months);
        System.out.println(weeks);
        System.out.println(days);

        //4.把某个信息减多少： minusYears  minusMonths minusWeeks minusDays
        LocalDate days1 = ld.minusDays(2);//2024-5-22
        LocalDate date1 = ld.minusYears(2);//2022-2-24
        System.out.println(date1);
        System.out.println(days1);

        //5.获取指定日期的LocalDate对象：public static LocalDate of(int year,int month,int dayOfMonth)
        LocalDate localDate = LocalDate.of(2025, 2, 5);
        LocalDate localDate1 = LocalDate.of(2025, 2, 5);


        //6.判断2个日期对象是否相等,在前还是在后：equals isBefore isAfter
        System.out.println(localDate.equals(localDate1));//true
        System.out.println(localDate1.equals(date1));//false
    }
}
